package cn.good.yan.service.t2;

import java.util.concurrent.*;

/**
 * 2. FutureTash 定义操作 - 异步任务
 * 1. Future  异步执行逻辑
 *
 * @author shengren.yan
 * @create 2024-03-23
 */
public class FutureDemo1 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> futureTask = new FutureTask<>(new MyThread());
        Thread t1 = new Thread(futureTask, "t1");
        t1.start();
        // 调用返回参数
        System.out.println(futureTask.get());
    }

}

// 该线程 - 有返回参数
class MyThread implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("执行这个线程 - 代码逻辑。。。");
        return "hello 带返回值的";
    }
}
